<?php

include '../../db.php';
$connect = pg_connect($connectionString);
if (!$connect) {
    echo "connect : A connection to the server could not be established!";
    return false;
}

$params = array();
array_push($params, pg_escape_string($_GET["id"]));
$stmt = pg_prepare($connect, "read_sale_header", "SELECT 
  sale_detail.total, 
  sale_detail.price, 
  sale_detail.quantity, 
  sale_detail.id, 
  warehouse_product.fullname
FROM 
  public.sale_detail, 
  public.warehouse_product
WHERE 
  sale_detail.product_id = warehouse_product.id AND sale_detail.header_id = $1;");
$result = pg_execute($connect, "read_sale_header", $params);

if (!$result) {
    die("Error in SQL query: " . pg_last_error());
}
$arrRegistros = pg_fetch_all($result);
echo json_encode($arrRegistros);
pg_free_result($result);
pg_close($connect);

